package com.aaa.service.impl;

import com.aaa.dao.DeptDao;
import com.aaa.entity.AlertCode;
import com.aaa.entity.Dept;
import com.aaa.service.DeptService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ：zhouhangyong
 * @date ：Created in 2022/6/23 8:42
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Resource
    DeptDao deptDao;

    @Override
    public AlertCode listDept(Map map) {
        int limit = Integer.parseInt(map.get("limit")+"");
        int page = Integer.parseInt(map.get("page") + "");
        page = (page-1) * limit;
        map.put("page",page);
        List<Dept> deptList = deptDao.deptList(map);
        for (Dept dept : deptList){
            System.out.println(dept.toString());
        }
        Integer integer = deptDao.deptListNum(map);
        return new AlertCode(0, "", integer, deptList);
    }

    @Override
    public AlertCode delete(String id) {
        Integer deleteDept = deptDao.deleteDept(id);

        if (deleteDept != null && deleteDept > 0) {
            return new AlertCode(0, "删除成功");
        } else {
            return new AlertCode(1, "删除失败");
        }
    }

    @Override
    public AlertCode add(Dept dept) {
        Integer addDept = deptDao.addDept(dept);
        if (addDept != null && addDept > 0){
            return new AlertCode(0,"添加成功");
        }else {
            return new AlertCode(1,"添加失败");
        }
    }

    @Override
    public AlertCode updateDept(Dept dept) {
        Integer addDept = deptDao.updateDept(dept);
        if (addDept != null && addDept > 0){
            return new AlertCode(0,"添加成功");
        }else {
            return new AlertCode(1,"添加失败");
        }
    }

    @Override
    public AlertCode updateKey(Integer id) {
        List<Dept> deptList = deptDao.deptKey(id);
        return new AlertCode(0, "", deptList);
    }

    // 唯一性校验ser
    @Override
    public List<Map> queryDeptname(String deptname, Integer deptid) {
        List<Map> list = deptDao.queryDeptname(deptname, deptid);
        return list;
    }
}
